package com.itheima.controller;

import com.itheima.pojo.Adopt;
import com.itheima.pojo.PageBean;
import com.itheima.pojo.Result;
import com.itheima.service.AdoptService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/adopt")
public class AdoptController {
    @Autowired
    private AdoptService adoptService;
    @PostMapping
    public Result add(@RequestBody @Validated Adopt adopt){
        adoptService.add(adopt);
        return Result.success();
    }
    @GetMapping
    public Result<PageBean<Adopt>> list(
            Integer pageNum,
            Integer pageSize,
            @RequestParam(required = false) Integer petId,
            @RequestParam(required = false) String status
    ){
        PageBean<Adopt> pb = adoptService.list(pageNum,pageSize,petId,status);
        return Result.success(pb);
    }
    @DeleteMapping
    public Result<Adopt> delete(Adopt adopt){
        adoptService.delete(adopt);
        return Result.success();
    }
}
